#pragma once

#include <string>

#include "cereal/types/memory.hpp"
#include "cereal/archives/binary.hpp"
#include "cereal/archives/json.hpp"
#include "cereal/types/vector.hpp"
#include "cereal/types/string.hpp"
#include "cereal/types/unordered_map.hpp"
#include "cereal/types/tuple.hpp"

namespace lurpc {

std::string uint32_to_bytes(uint32_t _x) {
    return { (char*)(&_x), 4 };
}

uint32_t bytes_to_uint32(const char* _buf) {
    return *((uint32_t*)_buf);
}

template<typename ... Args>
std::string serialize(const Args& ... _args) {
    std::tuple<Args...> _params(_args...);
    std::ostringstream os;
    cereal::BinaryOutputArchive arch(os);
    arch(_params);
    return os.str();
}

template<typename T>
T deserialize(const std::string& _buf) {
    T ans;
    std::istringstream is(_buf);
    cereal::BinaryInputArchive arch(is);
    arch(ans);
    return ans;
}

}
